package com.kexio.common.exception;

/**
 * 基础异常类
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public abstract class BaseException extends RuntimeException {
    
    /**
     * 错误码
     */
    private final Integer code;
    
    /**
     * 错误消息
     */
    private final String message;
    
    /**
     * 错误详情
     */
    private final String detail;
    
    public BaseException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
        this.detail = null;
    }
    
    public BaseException(Integer code, String message, String detail) {
        super(message);
        this.code = code;
        this.message = message;
        this.detail = detail;
    }
    
    public BaseException(Integer code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
        this.detail = cause != null ? cause.getMessage() : null;
    }
    
    public BaseException(Integer code, String message, String detail, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
        this.detail = detail;
    }
    
    public Integer getCode() {
        return code;
    }
    
    @Override
    public String getMessage() {
        return message;
    }
    
    public String getDetail() {
        return detail;
    }
    
    @Override
    public String toString() {
        return this.getClass().getSimpleName() + "{" +
                "code=" + code +
                ", message='" + message + '\'' +
                (detail != null ? ", detail='" + detail + '\'' : "") +
                '}';
    }
}
